<template>
  <div class="goods-item" @click="toDetail">
    <img v-lazy="goodsInfo.cover_url" alt="" />
    <!-- <img src="https://img01.yzcdn.cn/vant/ipad.jpeg" alt="" /> -->
    <div class="goods-info">
      <p>{{ goodsInfo.title }}</p>
      <span class="price"><small>￥</small>{{ goodsInfo.price }}</span>
      <span class="collect">{{ goodsInfo.stock }}</span>
    </div>
  </div>
</template>

<script>
import { useRouter } from 'vue-router'
export default {
  name: 'GoodsItem',
  props: {
    goodsInfo: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  setup(props) {
    const router = useRouter()
    function toDetail() {
      router.push({
        name: 'detail',
        params: {
          id: props.goodsInfo.id
        }
      })
    }
    return {
      toDetail
    }
  }
}
</script>

<style lang="scss" scoped>
.goods-item {
  width: 46%;
  padding-bottom: 0.4rem;
  text-align: center;
  img {
    width: 100%;
  }
  .goods-info {
    p {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      text-align: center;
    }
    .price {
      color: red;
      margin-right: 0.2rem;
    }
    .collect {
      position: relative;
    }
    .collect::before {
      content: '';
      left: -0.14rem;
      position: absolute;
      width: 0.12rem;
      height: 0.12rem;
      background: url('~assets/images/icon/shoucang.png') 0 0/0.12rem 0.12rem;
    }
  }
}
</style>